﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S_Gridding.Api;
using S_Incident.Infrasturctre;
using S_Userinfor.Domains;
using S_UserInfor.Api.Application.Commands;
using SqlSugar;

namespace S_UserInfor.Api.Controllers
{
    /// <summary>
    /// 测试SqlSugar增删改
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    { 
        private readonly SqlSugarInfor db;
        private readonly IMediator _mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        /// <param name="db"></param>
        public UserController(IMediator mediator, SqlSugarInfor db)
        {
            _mediator = mediator;
            this.db = db;
        }
        /// <summary>
        /// 表添加进mysql数据库中
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public string CreateTable()
        {
            db.CreateTable();
            return "ok";
        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int>Create(UserSqlSuageCeateCommands command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> DelCottage([FromQuery] UserSqlSuageDelCommands command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int> UpdUser(UserSqlSuageUpdCommands command)
        {
            return await _mediator.Send(command);
        }
    }
}
